﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Text;

namespace MedReg.Classes
{
    [Serializable]
    public class DiplomaEducation : ISerializable
    {
        private EducationInstitution graduatedFromField;

        private EducationType typeField;

        private decimal graduationDateField;

        private string diplomaSerieField;

        private string diplomaNumberField;

        private Speciality graduationSpecialityField;

        private static readonly DiplomaEducation theOneObject = new DiplomaEducation();

        private Employee employeeField;

        public static DiplomaEducation GetDiplomaEducation()
        {
            return theOneObject;
        }
        /// <remarks/>
        public EducationInstitution GraduatedFrom
        {
            get
            {
                return this.graduatedFromField;
            }
            set
            {
                this.graduatedFromField = value;
            }
        }

        /// <remarks/>
        public EducationType Type
        {
            get
            {
                return this.typeField;
            }
            set
            {
                this.typeField = value;
            }
        }

        /// <remarks/>
        public decimal GraduationDate
        {
            get
            {
                return this.graduationDateField;
            }
            set
            {
                this.graduationDateField = value;
            }
        }

        /// <remarks/>
        public string DiplomaSerie
        {
            get
            {
                return this.diplomaSerieField;
            }
            set
            {
                this.diplomaSerieField = value;
            }
        }

        /// <remarks/>
        public string DiplomaNumber
        {
            get
            {
                return this.diplomaNumberField;
            }
            set
            {
                this.diplomaNumberField = value;
            }
        }

        /// <remarks/>
        public Speciality GraduationSpeciality
        {
            get
            {
                return this.graduationSpecialityField;
            }
            set
            {
                this.graduationSpecialityField = value;
            }
        }

        public Employee Employee
        {
            get
            {
                return employeeField;
            }
            set
            {
                employeeField = value;
            }
        }

        [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            //throw new NotImplementedException();
            info.AddValue("GraduatedFrom", graduatedFromField);
            info.AddValue("EducationType", typeField);
            info.AddValue("GraduationDate", graduationDateField);
            info.AddValue("DiplomaSerie", diplomaSerieField);
            info.AddValue("DiplomaNumber", diplomaNumberField);
            info.AddValue("GraduationSpeciality", graduationSpecialityField);

        }
        public DiplomaEducation()
        {
        }
        public List<Classes.DiplomaEducation> getDiplomaEducationList(Classes.ArrayOfEmployee sEmployee)
        {

            foreach (var emp in sEmployee)
            {
                foreach (var DiplomaEducation in emp.EmployeeSpecialities)
                {
                    DiplomaEducation.Employee = emp;
                }
            }

            //var awd = sEmployee
            //    .SelectMany(award => award.EmployeeAwards, (Employees, Awards) => new { Employees, Awards })
            //    .Select(AwardsEx => new { Employee = AwardsEx.Employees, AwardsEx.Awards }).ToList();

            var cr = sEmployee.SelectMany(em => em.EmployeeSpecialities).ToList();

            return cr;
        }

    }
}
